Repository navigation
R50-T010: Strengthen the tests of OpenKnightTour (KnightTour.js) [Backtracking/KnightTour.js] - #108
Open
stavansomaiya wants to merge 1 commit into
Open
stavansomaiya wants to merge 1 commit into
stavansomaiya wants to merge 1 commit into
Conversation
This was referenced Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
e26b07f1064Backtracking/KnightTour.js→OpenKnightTour(line 3 at the pinned commit, line 3 after this PR)5c39e87·KnightTour.js#L3stavansomaiya:student/e26b07f1064/R50-T010→S-AI-Projects:master(one commit on5c39e87)Summary
Adds mutation-resistant regressions for
OpenKnightTourinBacktracking/KnightTour.js. Plausible one-line mistakes, applied only in temporary copies, pass the old tests on small inputs but fail the new ones for a semantic reason. The original passes them all.Files changed
Backtracking/KnightTour.jsBacktracking/tests/KnightTour.test.jswork/R50-T010/(8 files)check.pyrunner,README.mdwrite-up,evidence.mjs,results.jsonand logs; coursework only, kept out of any upstream PRRelated Issue
Fixes: #10
This PR covers only R50-T010. Each of the 10 tasks has its own branch, commit and PR; see All 10 tasks under Additional Notes.
Type of Change
Changes Made
Backtracking/tests/KnightTour.test.js: an independent tour checker (1..n² each exactly once, every step a knight move; it calls noOpenKnightTourmethod). Tests covern = 1(smallest), the 3×3 failed search leaving an all-zero board, the 5×5 solution being a valid open tour,getMoveskeeping moves onto row 0 / column 0 (reduced togetMoves([1, 2])on 3×3), and two fresh instances both producing the same explicit board.Backtracking/KnightTour.js: a comment documenting the protected backtracking condition. No logic change, no mutant, no test-only branch.work/R50-T010/:check.py(runs both mutants),evidence.mjsand results.Screenshots / Recordings
There is no UI, so the recording is the terminal output of a fresh run on 23 Nov 2026. The run used a clean checkout of this branch with a new
npm cifrom the lockfile. The output is copied verbatim; only the temporary checkout path is replaced by a label.Focused tests:
npx vitest run … --reporter=verbose, 7/7 passedAutomated check:
python3 work/R50-T010/check.py, exit 0Testing
Automated check:
python3 work/R50-T010/check.pyinstalls from the lockfile and runs the focused tests. It then prints input / expected / actual for every fixture row, runs each deliberate mutant in a temporary copy, and finally runs the repository test script in non-watch mode. It exits non-zero if any assertion or step fails, and records every command incommands.log.To reproduce:
Recorded results (committed in
results.json; tool versions inversions.txt):npm ci --ignore-scripts --no-audit --no-fundvitest run Backtracking/tests/KnightTour.test.jsnode work/R50-T010/evidence.mjscheck.pyfailed search on 3x3 leaves the board all zeroscheck.pygetMoves keeps moves onto row 0 and column 0npm test(vitest run)npm run check-style(Prettier)codespellAcceptance criteria → evidence:
OpenKnightTourin Backtracking/KnightTour.js; every assertion has an explicit expected value.false,[[0]], an all-zero 3×3 board,[[2, 0], [0, 0]], and the explicit 5×5 board[[19,4,15,10,25],…].OpenKnightTourfrom Backtracking/KnightTour.js. Write the literal inputs and independently calculated expected outputs in the tests before editing the implementation. The check must name the source line establishing each precondition.n = 1givessolve() === falseand board[[0]], because the start square is never numbered (line 38). Ordinary:n = 5givestruewith a valid open tour, verified by an independent checker. Preconditions cite lines 12-21 (move order), 25 (bounds) and 58 (reset).failed search on 3x3 leaves the board all zerosfails (board[[2,5,8],[7,0,3],[4,1,6]]). Withy > 0,getMoves keeps moves onto row 0 and column 0fails ([[2,0]]instead of[[2,0],[0,0]]).KnightTour.jsis a comment (lines 53-57). The mutants exist only in temporary copies made bycheck.py.Evidence files:
check.py·README.md(contract, fixture, baseline, findings) ·evidence.mjs·results.json·vitest-focused.jsonChecklist
Additional Notes
Removing the backtracking reset (line 58) leaves
[[2,5,8],[7,0,3],[4,1,6]]on the 3×3 board and failsfailed search on 3x3 leaves the board all zeros; on 5×5 it even returnstruewith repeated numbers.y >= 0→y > 0(line 25) failsgetMoves keeps moves onto row 0 and column 0. An equivalent mutant (x <= this.size) was identified and rejected. Possible follow-up:n = 1returnsfalsebecause the start square is never numbered (line 38); this is kept as-is because fixing it would change every pinned 5×5 board.Scope: the PR changes only
Backtracking/KnightTour.js, its test file andwork/R50-T010/.work/R50-T010/is coursework evidence and would be removed from any later upstream PR.All 10 tasks (one PR each)
R50-T001R50-T002R50-T003R50-T004R50-T005R50-T006R50-T007R50-T008R50-T009R50-T010